"""author: wangxin
   data: 2021/11/23
   project: homework
"""



try:
    import subprocess
    from IPy import IP

    a = input("请输入你要检查的网段，掩码：")
    ip = IP(a)
    for i in ip:
        result = subprocess.call(f"ping -c 1 {i}", shell=True)
        if result == 0:
            with open("ip.txt", "a+", encoding="utf-8") as fp:
                fp.write(f"{i}已被使用\n")
        if result == 1:
            with open("ip2.txt", "a+", encoding="utf-8") as fp1:
                fp1.write(f"{i}未被使用\n")
except ValueError:
    print("输入不合法")
except Exception:
    print("other False")
